package edu.jd.movieplatform.search.c_minprice;


import edu.jd.movieplatform.common.Result;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/search/c_minprice")
public class c_MinPriceAPI {


    @Resource
    private c_MinPriceService minPriceService;

    @RequestMapping("/minprice")
    public Result List(Integer id){


        float price;
        c_MinPriceDto dto = new c_MinPriceDto();
        List<c_MinPrice> list =minPriceService.getCinemaList();
        for(int i=0;i<list.size();i++)
        {
            dto.setMov_id(id);
            dto.setCnm_id(list.get(i).getCnm_id());
            if(minPriceService.getMinPrice(dto) != null)
            {
                price=minPriceService.getMinPrice(dto);
                list.get(i).setPrice(price);
            }
        }
        for(int i=list.size()-1;i>=0;i--)
        {
            if(list.get(i).getPrice() == null)
            {
                list.remove(i);
            }
        }
        return Result.success(list);
    }


}
